﻿using System.Globalization;
using System.Reflection;
using System.Resources;

namespace ThunderboltHelper.Language;

public class StringResourceManager
{
	/// <summary>
	/// 当前语言信息
	/// </summary>
	public static CultureInfo CultureInfo { get; set; }
	/// <summary>
	/// 获取字符串
	/// </summary>
	/// <param name="name"></param>
	/// <returns></returns>
	public static string GetString(Type type, string name)
	{
		ResourceManager resource;
		var assembly = type.Assembly;
		if (_resourceDic.ContainsKey(assembly))
		{
			resource = _resourceDic[assembly];
		}
		else
		{
			string ex = "Extension";
			resource = new ResourceManager(type.FullName.Substring(0, type.FullName.Length - ex.Length), assembly);
			_resourceDic.Add(assembly, resource);
		}
	
		return resource.GetString(name, CultureInfo);
	}

	private static Dictionary<Assembly, ResourceManager> _resourceDic = new Dictionary<Assembly, ResourceManager>();

}